package com.wangyh.edit.prettyedit.util;

import com.wangyh.edit.prettyedit.constant.EditConstant;
import com.wangyh.edit.prettyedit.mainframe.MainFrameView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.io.File;

public class FileImgUtils {

    public static ImageView getFileImageView(File file){
        String name = file.getName();
        Image image = null;
        int index = name.lastIndexOf(".");
        String type = name.substring(index+1, name.length());
        if(type!=null && type.trim().length()>0){
            if("txt".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/txt.png"));
            }else if("json".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/json.png"));
            }else if("xml".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/xml.png"));
            }else if("sh".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/sh.png"));
            }else if("conf".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/conf.png"));
            }else if("doc".equals(type) || "docx".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/doc.png"));
            }else if("pdf".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/pdf.png"));
            }else if("ppt".equals(type)||"pptx".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/ppt.png"));
            }else if("html".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/html.png"));
            }else if("md".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/md.png"));
            }else if("xlsx".equals(type)||"xls".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/xls.png"));
            }else if("flow".equals(type)){
                image = new Image(MainFrameView.class.getResourceAsStream("/img/flow.png"));
            }else{
                image = new Image(MainFrameView.class.getResourceAsStream("/img/file.png"));
            }
        }else{
            image = new Image(MainFrameView.class.getResourceAsStream("/img/file.png"));
        }

        ImageView fileIcon = new ImageView(image);
        fileIcon.setFitHeight(EditConstant.treeIconHeight);
        fileIcon.setFitWidth(EditConstant.treeIconWeight);

        return fileIcon;
    }
}
